/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.dp.controller;

import com.dp.model.Books;
import com.dp.services.IItemServices;
import com.dp.services.ItemServices;
import com.dp.utils.BaseException;
import com.dp.dto.BookAddDTO;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 *
 * @author hisik
 */
public class BookAddController {
    
    private static final IItemServices itemServices = new ItemServices();
        
    public static void saveNewBook(BookAddDTO dto) throws BaseException {
        
        Long objid              = dto.getObjid();
        String issueArea        = dto.getIssueArea();
        int issueDate           = dto.getIssueDate();
        int authorCount         = dto.getAuthorCount();
        String bookName         = dto.getBookName();
        String authorName       = dto.getAuthorName();
        String isbn             = dto.getIsbn();
        int pageCount           = dto.getPageCount();
        String publisherName    = dto.getPublisherName();
        
        Calendar c = new GregorianCalendar();
        c.set(Calendar.YEAR, issueDate);
        Date date = c.getTime();
        
        itemServices.saveOrUpdateBooks(objid, authorCount, authorName, bookName, isbn, 
                issueArea, date, pageCount,  publisherName);
    }
    
    public static Books getBooksByObjid(BookAddDTO dto) throws BaseException {
        Long objid = dto.getObjid();
        
        return itemServices.getBooksByObjid(objid);
    }
}
